package org.yaukie.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Locale.Category;

public class DateTime extends Date {
    private static final long serialVersionUID = 1L;

    public static DateTime now() {
        return new DateTime();
    }

    public DateTime() {
    }

    public DateTime(Date date) {
        this(date.getTime());
    }

    public DateTime(Calendar calendar) {
        this(calendar.getTime());
    }

    public DateTime(long timeMillis) {
        super(timeMillis);
    }

    public int getField(DateField field) {
        return this.getField(field.getValue());
    }

    public int getField(int field) {
        return this.toCalendar().get(field);
    }

    public int year() {
        return this.getField(DateField.YEAR);
    }

    public int season() {
        return this.monthStartFromOne() / 3 + 1;
    }

    public int month() {
        return this.getField(DateField.MONTH);
    }

    public int monthStartFromOne() {
        return this.month() + 1;
    }

    public int weekOfYear() {
        return this.getField(DateField.WEEK_OF_YEAR);
    }

    public int weekOfMonth() {
        return this.getField(DateField.WEEK_OF_MONTH);
    }

    public int dayOfMonth() {
        return this.getField(DateField.DAY_OF_MONTH);
    }

    public int dayOfWeek() {
        return this.getField(DateField.DAY_OF_WEEK);
    }

    public int dayOfWeekInMonth() {
        return this.getField(DateField.DAY_OF_WEEK_IN_MONTH);
    }

    public int hour(boolean is24HourClock) {
        return this.getField(is24HourClock ? DateField.HOUR_OF_DAY : DateField.HOUR);
    }

    public int minute() {
        return this.getField(DateField.MINUTE);
    }

    public int second() {
        return this.getField(DateField.SECOND);
    }

    public int millsecond() {
        return this.getField(DateField.MILLISECOND);
    }

    public Calendar toCalendar() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(this);
        return cal;
    }

    public Calendar toCalendar(Locale locale) {
        Calendar cal = Calendar.getInstance(locale);
        cal.setTime(this);
        return cal;
    }

    public Calendar toCalendar(TimeZone zone) {
        return this.toCalendar(zone, Locale.getDefault(Category.FORMAT));
    }

    public Calendar toCalendar(TimeZone zone, Locale locale) {
        Calendar cal = Calendar.getInstance(zone, locale);
        cal.setTime(this);
        return cal;
    }
}
